//
//  NetWorkTool.m
//  YunGou
//
//  Created by macbook on 16/5/26.
//  Copyright © 2016年 macbook. All rights reserved.
//

#import "NetWorkTool.h"
#import "NSString+Regexp.h"
#import <CommonCrypto/CommonDigest.h>

#define SingletonManager [NetWorkTool shareInstance]

@implementation NetWorkTool

//设置单例
+ (NetWorkTool *)shareInstance{
    __strong static NetWorkTool *sharedManager;
    
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        sharedManager = [[NetWorkTool alloc] init];
    });
    return sharedManager;
}

#pragma -mark 首页
//头部滚动视图
+ (void)topScrollViewWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=index" withParaments:nil withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}
//热门推荐
+ (void)hotRecommendWithStart:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=remen_tuijian" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}
//新品
+ (void)newProductsWithStart:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=new_products" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//闪夺
+ (void)shanDuoWithStart:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=shan_duo" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
    
}

//巧夺
+ (void)qiaoDuoWithStart:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=qiao_duo" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//晒单
+ (void)shaiDanWithWithIsMine:(BOOL)isMine start:(NSInteger)start Success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = nil;
    if (isMine) {
        body = [NSString stringWithFormat:@"uid=%@&start=%ld&count=10",[UserModel sharedInstance].uid,start];
    }else{
        body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    }
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=shai_dan" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//晒单添加评论
+ (void)addCommentWithSdId:(NSString *)sd_id username:(NSString *)username content:(NSString *)contnet success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&user_name=%@&sd_id=%@&content=%@",[UserModel sharedInstance].uid,username,sd_id,contnet];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=ping_lun" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//评论列表
+ (void)commentListWithSdId:(NSString *)sd_id success:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=pinglun_liebiao" withParaments:@{@"sd_id":sd_id} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//最新揭晓
+ (void)mainLatestAnnounceWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=zuixin_jiexiao" withParaments:nil withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 分类
//分类类别
+ (void)categoryTypeWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=fen_lei" withParaments:nil withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//分类商品列表
+ (void)categoryListWithCategoryId:(NSString *)categoryId sortId:(NSString *)sortId start:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = nil;
    if (categoryId) {
        body = [NSString stringWithFormat:@"cateid=%@&start=%ld&count=10",categoryId,start];
    }else if (sortId){
        body = [NSString stringWithFormat:@"sort=%@&start=%ld&count=10",sortId,start];
    }else{
        body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    }
    
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=fenlei_goods_list" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 最新揭晓
+ (void)latestAnnounceWithStart:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&count=10",start];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=zhu_zuixin_jiexiao" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 购物车
//添加购物车
+ (void)addShopCartWithGoodsId:(NSString *)goodsId success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&id=%@",[UserModel sharedInstance].uid,goodsId];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=jiaru_gouwuche" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//购物车列表
+ (void)shopCartListWithSuceess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=gouwu_che" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//删除购物车
+ (void)deleteShopCartWithGoodsId:(NSString *)goodsId success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&id=%@",[UserModel sharedInstance].uid,goodsId];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=gouwuche_del" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//修改购物车商品数量
+ (void)updateShopCartWithGoodsId:(NSString *)goodsId goodsNum:(NSString *)goodsNum success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&id=%@&goods_num=%@",[UserModel sharedInstance].uid,goodsId,goodsNum];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=xiugai_sp_shuliang" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//结算
+ (void)balanceAccountWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=jie_suan" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 商品详情子内容相关
//商品详情晒单分享
+ (void)shaiDanFenXiangWithGoodsId:(NSString *)goodsId start:(NSInteger)start success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"start=%ld&id=%@&count=10",start,goodsId];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=shaidan_fenxiang" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];

}

//计算详情
+ (void)calculateInfoWithGoodsId:(NSString *)goodsId success:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=jisuan_xiangqing" withParaments:@{@"id":goodsId} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//所有参与记录
+ (void)enjoyRecordWithGoodsId:(NSString *)goodsId success:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=all_enjoy_record" withParaments:@{@"id":goodsId} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 支付
//三方支付
+ (void)payWithOrderNo:(NSString *)orderNo Channel:(NSString *)channel amount:(NSString *)amount success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"order_no=%@&channel=%@&amount=%@",orderNo,channel,amount];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=PingPay&a=index" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//余额支付
+ (void)payMoneyWithCode:(NSString *)code success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&code=%@",[UserModel sharedInstance].uid,code];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=jiesuan_yu" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}



#pragma -mark 我的
//我的收获地址
+ (void)myReceiveAddressWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=shouhuo_dizhi" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//添加收货地址
+ (void)addReceiveAddressWithShouHuoren:(NSString *)shouHuoRen mobile:(NSString *)mobile address:(NSString *)address jieDao:(NSString *)jieDao code:(NSString *)code isDefault:(NSString *)isDefault success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&shouhuoren=%@&mobile=%@&sheng=%@&jiedao=%@&youbian=%@&default=%@",[UserModel sharedInstance].uid,shouHuoRen,mobile,address,jieDao,code,isDefault];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=tianjia_dizhi" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//删除收获地址
+ (void)deleteReceiveAddressWithAddressId:(NSString *)addressId success:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=delete_dizhi" withParaments:@{@"id":addressId} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//编辑收获地址
+ (void)editReceiveAddressWithId:(NSString *)Id houHuoren:(NSString *)shouHuoRen mobile:(NSString *)mobile address:(NSString *)address jieDao:(NSString *)jieDao code:(NSString *)code isDefault:(NSString *)isDefault success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&id=%@&shouhuoren=%@&mobile=%@&sheng=%@&jiedao=%@&youbian=%@&default=%@",[UserModel sharedInstance].uid,Id,shouHuoRen,mobile,address,jieDao,code,isDefault];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=bianji_dizhi" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//云购记录
+ (void)buyRecordWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=yungou_jilu" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//充值记录
+ (void)rechargeRecordWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=chongzhi_jilu" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//中奖记录
+ (void)winRecordWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=zhongjiang_jilu" withParaments:@{@"uid":@"7"} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//添加晒单分享
+ (void)addShareOrderWithGoodsId:(NSString *)goodsId sd_issue:(NSString *)sd_issue sd_ip:(NSString *)sd_ip sd_title:(NSString *)sd_title sd_content:(NSString *)sd_content sd_photoList:(NSString *)sd_photoList success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"sd_userid=%@&sd_shopid=%@&sd_qishu=%@&sd_ip=%@&sd_title=%@&sd_content=%@&sd_photolist=%@",[UserModel sharedInstance].uid,goodsId,sd_issue,sd_ip,sd_title,sd_content,sd_photoList];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=yonghu_shaidan" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//编辑用户信息
+ (void)updateUserInfoWithNickName:(NSString *)nickName img:(NSString *)img gender:(NSString *)gender birth:(NSString *)birth qq:(NSString *)qq email:(NSString *)email address:(NSString *)address success:(requestSuccess)success failure:(requestFailure)failure{
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    [parameters setObject:[UserModel sharedInstance].uid forKey:@"uid"];
    if (nickName) {
        [parameters setObject:nickName forKey:@"username"];
    }
    if (img) {
        [parameters setObject:img forKey:@"img"];
    }
    if (gender) {
        [parameters setObject:gender forKey:@"gender"];
    }
    if (birth) {
        [parameters setObject:birth forKey:@"birth"];
    }
    if (email) {
        [parameters setObject:email forKey:@"email"];
    }
    if (qq) {
        [parameters setObject:qq forKey:@"qq"];
    }
    if (address) {
        [parameters setObject:address forKey:@"address"];
    }
    
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=geren_zl_bianji" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//修改密码
+ (void)changePwdWithMobile:(NSString *)mobile oldPwd:(NSString *)oldPwd newPwd:(NSString *)newPwd success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"mobile=%@&ori_pass=%@&new_pass=%@",mobile,oldPwd,newPwd];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=anquan_xg_mima" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//更换手机号
+ (void)changeMobileWithOldMobile:(NSString *)oldMobile newMobile:(NSString *)newMobile password:(NSString *)password success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"ori_mobile=%@&ori_pass=%@&new_mobile=%@",oldMobile,password,newMobile];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=anquan_xg_shouji" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//意见反馈
+ (void)feedBackWithContent:(NSString *)content success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"uid=%@&feedback_info=%@",[UserModel sharedInstance].uid,content];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Index&a=anquan_fankui" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//账户余额
+ (void)userAccountWithSuccess:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:0 withUrlString:@"m=Home&c=Index&a=zhifu_yu" withParaments:@{@"uid":[UserModel sharedInstance].uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

#pragma -mark 用户相关
//注册
+ (void)registerWithPhone:(NSString *)phone password:(NSString *)password success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"phone=%@&pass=%@",phone,password];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Public&a=register" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//登录
+ (void)loginWithPhone:(NSString *)phone password:(NSString *)password success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"phone=%@&pass=%@",phone,password];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Public&a=login" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//三方登录
+ (void)thirdLoginWithThirdPartyUid:(NSString *)uid success:(requestSuccess)success failure:(requestFailure)failure{
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Public&a=sanfang_xinxi" withParaments:@{@"user_id":uid} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//忘记密码
+ (void)forgetPasswordWithPhone:(NSString *)phone password:(NSString *)password success:(requestSuccess)success failure:(requestFailure)failure{
    NSString *body = [NSString stringWithFormat:@"phone=%@&pass=%@",phone,password];
    NSDictionary *parameters = [SingletonManager parametersWithHTTPBody:body];
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Public&a=get_back_password" withParaments:parameters withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
}

//获取验证码
+ (void)sendVerfiWithPhone:(NSString *)tel content:(NSString *)content success:(requestSuccess)success failure:(requestFailure)failure{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager.requestSerializer willChangeValueForKey:@"timeoutInterval"];
    manager.requestSerializer.timeoutInterval = 10;
    [manager.requestSerializer didChangeValueForKey:@"timeoutInterval"];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain",nil];
    
    NSMutableString* muStr = [[NSMutableString alloc]init];
    if (nil != tel) {
        [muStr appendFormat:@"m=%@",tel];
    }
    if (nil != content) {
        [muStr appendFormat:@"&c=%@",content];
    }
    
    NSDictionary* parameters = [SingletonManager parametersWithHTTPBody:muStr];
    [manager POST:[NSString stringWithFormat:@"http://api.smsbao.com/sms?u=3393055606&p=%@&",@"13911893686"] parameters:parameters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if (success) {
            success(responseObject);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failure) {
            failure(error);
        }
    }];
}


#pragma -mark 辅助函数
//上传图片
+ (void)uploadWithImage:(UIImage *)img success:(requestSuccess)success failure:(requestFailure)failure{
    NSData *data = UIImageJPEGRepresentation(img, 0.05);
    [NetWorkManager requestWithType:1 withUrlString:@"m=Home&c=Uplode&a=Uplodeimg" withParaments:@{@"img":[data base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]} withSuccessBlock:^(id object) {
        if (success) {
            success(object);
        }
    } withFailureBlock:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    } progress:^(float progress) {
        
    }];
    
}

- (NSDictionary *)parametersWithHTTPBody:(NSString *)body
{
    NSArray *array = [body componentsSeparatedByString:@"&"];
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    for(NSString *str in array)
    {
        NSString *key   = [str componentsSeparatedByString:@"="][0];
        NSString *value = [str componentsSeparatedByString:@"="][1];
        
        [parameters setValue:value forKey:key];
    }
    return parameters;
}

- (NSString *)getMd5_32Bit_String:(NSString *)srcString {
    //追加私钥
    srcString = [NSString addSuffix:@"" withString:srcString];
    const char *cStr = [srcString UTF8String];
    unsigned char digest[CC_MD5_DIGEST_LENGTH];
    CC_MD5( cStr, strlen(cStr), digest );
    NSMutableString *result = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
    for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++)
        [result appendFormat:@"%02x", digest[i]];
    
    return result;
}


@end
